package com.woniu.user.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.result.Result;
import com.woniu.user.client.UserVIPQueryClient;
import com.woniu.user.client.result.UserVipRelationResultInfo;
import com.woniu.user.client.result.VipResultInfo;
import com.woniu.user.service.UserVipRelationService;
import com.woniu.user.service.VipService;
import com.woniu.user.service.dto.UserVipRelationDto;
import com.woniu.user.service.dto.VipDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
public class VIPCardInfoApiImpl implements UserVIPQueryClient {
    @Resource
    private VipService vipService;

    @Resource
    private UserVipRelationService userVipRelationService;
    //查看所有的VIP卡在售
    @Override
    public Result getVipCartInfo() {
        List<VipDto> vipDtos = vipService.vipCardInfo();
        List<VipResultInfo> vipResultInfos = BeanUtil.copyToList(vipDtos, VipResultInfo.class);
        return Result.getInstance(List.class).setData(vipResultInfos);
    }
    //查看用户现有的会员卡
    @Override
    public Result<List<UserVipRelationResultInfo>> getUserVipCard(Integer userId) {
        log.info("检查用户Id:{}", userId);
        List<UserVipRelationDto> userVipCard = userVipRelationService.getUserVipCard(userId);
        List<UserVipRelationResultInfo> userVipRelationResultInfos = BeanUtil.copyToList(userVipCard, UserVipRelationResultInfo.class);
        return Result.getInstanceList(UserVipRelationResultInfo.class).setData(userVipRelationResultInfos);
    }
}
